﻿/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:Bymed.SpineScan.WPF.ViewModel"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
*/

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;
using Bymed.SpineScan.WPF.Model;

namespace Bymed.SpineScan.WPF.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// See http://www.galasoft.ch/mvvm
    /// </para>
    /// </summary>
    public class ViewModelLocator
    {
        static ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            if (ViewModelBase.IsInDesignModeStatic)
            {
                SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
            }
            else
            {
                SimpleIoc.Default.Register<IDataService, DataService>();
            }

            SimpleIoc.Default.Register<MainViewModel>();
            SimpleIoc.Default.Register<PatientBasicInfoViewModel>();
            SimpleIoc.Default.Register<PatientDataSearchViewModel>();
            SimpleIoc.Default.Register<SelectTestItemViewModel>();
            SimpleIoc.Default.Register<StartTestViewModel>();
            SimpleIoc.Default.Register<TestSummaryViewModel>();
            SimpleIoc.Default.Register<TestReportViewModel>();
            SimpleIoc.Default.Register<SingleTestDetailViewModel>();
            SimpleIoc.Default.Register<HistoryDataAnalysisViewModel>();
            SimpleIoc.Default.Register<DataManagementViewModel>();
            SimpleIoc.Default.Register<CustomizedTestItemViewModel>();
            SimpleIoc.Default.Register<AttendingDoctorSetupViewModel>();
            SimpleIoc.Default.Register<DiagnosticMessageReferenceSetupViewModel>();
            SimpleIoc.Default.Register<BasicConfigurationViewModel>();
            SimpleIoc.Default.Register<DeviceConfigurationViewModel>();
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel Main
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }

        /// <summary>
        /// Gets the PatientBasicInfo property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public PatientBasicInfoViewModel PatientBasicInfo
        {
            get
            {
                return ServiceLocator.Current.GetInstance<PatientBasicInfoViewModel>();
            }
        }

        /// <summary>
        /// Gets the PatientDataSearch property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public PatientDataSearchViewModel PatientDataSearch
        {
            get
            {
                return ServiceLocator.Current.GetInstance<PatientDataSearchViewModel>();
            }
        }

        /// <summary>
        /// Gets the SelectTestItem property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public SelectTestItemViewModel SelectTestItem
        {
            get
            {
                return ServiceLocator.Current.GetInstance<SelectTestItemViewModel>();
            }
        }

        /// <summary>
        /// Gets the StartTest property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public StartTestViewModel StartTest
        {
            get
            {
                return ServiceLocator.Current.GetInstance<StartTestViewModel>();
            }
        }

        /// <summary>
        /// Gets the TestSummaryReport property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public TestSummaryViewModel TestSummary
        {
            get
            {
                return ServiceLocator.Current.GetInstance<TestSummaryViewModel>();
            }
        }

        /// <summary>
        /// Gets the TestReport property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public TestReportViewModel TestReport
        {
            get
            {
                return ServiceLocator.Current.GetInstance<TestReportViewModel>();
            }
        }

        /// <summary>
        /// Gets the TestReport property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public SingleTestDetailViewModel SingleTestDetail
        {
            get
            {
                return ServiceLocator.Current.GetInstance<SingleTestDetailViewModel>();
            }
        }

        /// <summary>
        /// Gets the HistoryDataAnalysis property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public HistoryDataAnalysisViewModel HistoryDataAnalysis
        {
            get
            {
                return ServiceLocator.Current.GetInstance<HistoryDataAnalysisViewModel>();
            }
        }

        /// <summary>
        /// Gets the DataManagement property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public DataManagementViewModel DataManagement
        {
            get
            {
                return ServiceLocator.Current.GetInstance<DataManagementViewModel>();
            }
        }

        /// <summary>
        /// Gets the AttendingDoctorSetup property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public CustomizedTestItemViewModel CustomizedTestItem
        {
            get
            {
                return ServiceLocator.Current.GetInstance<CustomizedTestItemViewModel>();
            }
        }

        /// <summary>
        /// Gets the AttendingDoctorSetup property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public AttendingDoctorSetupViewModel AttendingDoctorSetup
        {
            get
            {
                return ServiceLocator.Current.GetInstance<AttendingDoctorSetupViewModel>();
            }
        }

        /// <summary>
        /// Gets the DiagnosticMessageReferenceSetup property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public DiagnosticMessageReferenceSetupViewModel DiagnosticMessageReferenceSetup
        {
            get
            {
                return ServiceLocator.Current.GetInstance<DiagnosticMessageReferenceSetupViewModel>();
            }
        }

        /// <summary>
        /// Gets the BasicConfiguration property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public BasicConfigurationViewModel BasicConfiguration
        {
            get
            {
                return ServiceLocator.Current.GetInstance<BasicConfigurationViewModel>();
            }
        }

        /// <summary>
        /// Gets the DeviceConfiguration property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public DeviceConfigurationViewModel DeviceConfiguration
        {
            get
            {
                return ServiceLocator.Current.GetInstance<DeviceConfigurationViewModel>();
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            // Unregister will call Cleanup in ViewModelBase.
            SimpleIoc.Default.Unregister<MainViewModel>();
            SimpleIoc.Default.Unregister<PatientBasicInfoViewModel>();
            SimpleIoc.Default.Unregister<PatientDataSearchViewModel>();
            SimpleIoc.Default.Unregister<SelectTestItemViewModel>();
            SimpleIoc.Default.Unregister<StartTestViewModel>();
            SimpleIoc.Default.Unregister<TestSummaryViewModel>();
            SimpleIoc.Default.Unregister<TestReportViewModel>();
            SimpleIoc.Default.Unregister<SingleTestDetailViewModel>();
            SimpleIoc.Default.Unregister<HistoryDataAnalysisViewModel>();
            SimpleIoc.Default.Unregister<DataManagementViewModel>();
            SimpleIoc.Default.Unregister<CustomizedTestItemViewModel>();
            SimpleIoc.Default.Unregister<AttendingDoctorSetupViewModel>();
            SimpleIoc.Default.Unregister<DiagnosticMessageReferenceSetupViewModel>();
            SimpleIoc.Default.Unregister<BasicConfigurationViewModel>();
            SimpleIoc.Default.Unregister<DeviceConfigurationViewModel>();
        }
    }
}